package com.singzi.leetcode.N600;

import java.util.List;
import java.util.Map;

public class T0539 {
    public static void main(String[] args) {
        Solution0539 solution0539 = new Solution0539();
        System.out.println(solution0539.timeSpace("02:59", "00:00"));
    }
}
class Solution0539 {
    public int findMinDifference(List<String> timePoints) {
        int result = Integer.MAX_VALUE;
        for (int i = 0; i < timePoints.size(); i++) {
            for (int j = i+1; j < timePoints.size(); j++) {
                if(timeSpace(timePoints.get(i), timePoints.get(j)) < result){
                    result = timeSpace(timePoints.get(i), timePoints.get(j));
                    if(result == 0) return 0;
                }
            }
        }
        return result;

    }
    public int timeSpace(String time0, String time1){
        int timeMinute0 = Integer.parseInt(time0.substring(0,2))*60 + Integer.parseInt(time0.substring(3,5));
        int timeMinute1 = Integer.parseInt(time1.substring(0,2))*60 + Integer.parseInt(time1.substring(3,5));
        int minuteSpace = Math.abs(timeMinute0 - timeMinute1);
        if(minuteSpace > 12*60) return 24*60-minuteSpace;
        else return minuteSpace;
    }
}